package playing_with_wheels;

import java.io.IOException;
import java.util.ArrayList;

/*
 * Problem ID: 10067
 * Problem Name: Playing With Wheels
 * Author: Kenny Chong
 * Date: 5/14/2012
 */
class Main implements Runnable
{
	static String ReadLn(int maxLength) 
    {
        byte line[] = new byte[maxLength];
        int length = 0;
        int input = -1;
        try {
            while (length < maxLength) {
                input = System.in.read();
                if ((input < 0) || (input == '\n'))
                    break;
                line[length++] += input;
            }

            if ((input < 0) && (length == 0))
                return null;
            return new String(line, 0, length);
        } catch (IOException e) {
            return null;
        }
    }
	
	public static void main(String [] args)
	{
		Main myMain = new Main();
		myMain.run();
	}
	
	public void run()
	{
		new Wheels().run();
	}
}

class Wheels implements Runnable
{
	static final int MAX_LENGTH = 1050;
	
	public void run() 
	{
		// Read number of test cases.
		int testCases = Integer.parseInt(Main.ReadLn(MAX_LENGTH).trim());
		
		// Read blank line.
		Main.ReadLn(MAX_LENGTH);
		
		// Implement graph for traversal.
		Graph<String> graph;
		
		for (int i = 0; i < testCases; i++)
		{
			String startConfig = Main.ReadLn(MAX_LENGTH).trim();
			String endConfig = Main.ReadLn(MAX_LENGTH).trim();
			
			int badNums = Integer.parseInt(Main.ReadLn(MAX_LENGTH).trim());
			
			String [] forBiddenNums = new String[badNums];
			
			for (int j = 0; j < badNums; j++)
			{
				String forBiddenNum = Main.ReadLn(MAX_LENGTH).trim();
				
				forBiddenNums[j] = forBiddenNum;
			}
			
			calculateResults();
		}
	}
	
	public void calculateResults()
	{
		
	}
	
	public Graph<String> createGraph(int maxVertices)
	{
		Graph<String> graph = new Graph<String>(maxVertices);
		
		ArrayList<String> neighbors;
		
		for (int i = 0; i < maxVertices; i++)
		{
			
		}
		
		return null;
	}
	
	public ArrayList<String> deterNearestVals(int num)
	{
		
		return null;
	}
}

class Graph<E>
{
	private boolean [][] edges;
	private E[] labels;
	
	public Graph(int n)
	{
		edges = new boolean[n][n];
		labels = (E[]) new Object[n];
	}
	
	public void addEdge(int source, int target)
	{
		edges[source][target] = true;
	}
	
	public E getLabel(int vertex)
	{
		return labels[vertex];
	}
	
	public boolean isEdge(int source, int target)
	{
		return edges[source][target];
	}
	
	public int[] neighbors (int vertex)
	{
		int i;
		int count;
		int [] answer;
		
		// First count how many edges have the vertex as their source.
		count = 0;
		
		for (i = 0; i < labels.length; i++)
		{
			if (edges[vertex][i])
				count++;
		}
		
		// Allocate the array for the answer.
		answer = new int[count];
		
		// Fill the array for the answer.
		count = 0;
		for (i = 0; i < labels.length; i++)
		{
			if (edges[vertex][i])
			{
				answer[count++] = i;
			}
		}
		
		return answer;
	}
	
	public void removeEdge(int source, int target)
	{
		edges[source][target] = false;
	}
	
	public void setLabel(int vertex, E newLabel)
	{
		labels[vertex] = newLabel;
	}
	
	public int size()
	{
		return labels.length;
	}
}